#include "window_common.h"

#if defined(GKT_CONFIG_WINDOW_DUAL_VERIFY_ENABLE) && GKT_CONFIG_WINDOW_DUAL_VERIFY_ENABLE
enum {
	WIDGET_ID_LIST = 0,
	WIDGET_ID_MAX
};

static const gkt_widget_list_item_s sc_window_dual_verify_list_items[] = {
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_VOICE_COMBINED_ID(close), WINNDOW_SWITCH_ACTION_CLOSE),
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_VOICE_COMBINED_ID(open), WINNDOW_SWITCH_ACTION_OPEN),
};

#define WINDOW_UNLOCK_MODE_LIST_ITEM_NUMS	\
	sizeof(sc_window_dual_verify_list_items) / sizeof(gkt_widget_list_item_s)

static const gkt_widget_list_attr_s sc_window_dual_verify_list_attr = 
	GKT_WIDGET_LIST_STATIC_ATTR(WINDOW_UNLOCK_MODE_LIST_ITEM_NUMS, 
		sc_window_dual_verify_list_items);

GKT_WINDOW_WIDGET_DESCS_DEFINE(dual_verify) = {
	[WIDGET_ID_LIST] = GKT_WIDGET_LIST_DESC(0, &sc_window_dual_verify_list_attr),
};

static uint8_t dual_verify_play_over=0;
static int window_dual_verify_event_handler(
				uint32_t major_type, uint32_t minor_type, 
				uint32_t id, uint32_t data)
{
	int dual_verify_enable;
	int retval = GKT_EVENT_HANDLE_CONTINUE;
	uint32_t voice_flags = GKT_WINDOW_VOICE_F_NOTIFY_END | GKT_WINDOW_VOICE_F_NOTIFY_ERROR;
	uint32_t combined_id;
	
	switch(major_type) {
		case GKT_EVENT_WINDOW:
			if (minor_type == GKT_WINDOW_ACTIVE)
				window_common_mask_except_number_repeat_return(WINDOW_UNLOCK_MODE_LIST_ITEM_NUMS);
			break;
		case GKT_EVENT_WIDGET:
			if(minor_type == GKT_WIDGET_EVENT_CLICK) {
				dual_verify_enable = (int)sc_window_dual_verify_list_items[data].data;
				if (dual_verify_enable != gp_window_data->dual_verify_enable) {
					gp_window_data->dual_verify_enable = dual_verify_enable;
					window_data_save();
				}

				dual_verify_play_over = 1;
				combined_id = WINDOW_VOICE_COMBINED_ID(set_success);
				gkt_window_voice_play(NULL, combined_id, voice_flags, NULL);
			}
			break;

		case GKT_EVENT_VOICE:
			if (dual_verify_play_over == 1) {
				dual_verify_play_over = 0;
				gkt_window_exit();
			}
			break;
		default:
			break;
	}

	return retval;
}
GKT_WINDOW_DESC_DEFINE(dual_verify);

#endif

